import {Component, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';

@Component({
  selector: 'app-product',
  templateUrl: './product.component.html',
  styleUrls: ['./product.component.css']
})
export class ProductComponent implements OnInit {

  private id: string;
  private name: string;

  constructor(private route: ActivatedRoute) {
  }

  ngOnInit() {
    // rxjs语法，params类型为Params
    this.route.params.subscribe(params => this.id = params['id']);
    this.route.data.subscribe((data: { product: Product }) => {
      this.id = data.product.id;
      this.name = data.product.name;
    });

  }

}

export class Product {
  constructor(public id: string, public name: string) {
  }
}
